<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>无标题文档</title>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css" media="all" />
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" type="text/css" />
  <script src="${pageContext.request.contextPath}/layui/jquery2.1.1.js"></script>
  <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
  <style type="text/css">
    .layui-form-item i{
      display: block;
      margin-top: 10px;
    }
  </style>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>采购管理</li>
    <li>商品类型管理</li>
    <li>添加</li>
  </ul>
</div>
<form class="layui-form" action="">
<div class="formbody">
  <div class="formtitle"><span>商品类型信息</span></div>
  <div class="layui-form-item">
    <label class="layui-form-label">品牌名称</label>
    <div class="layui-input-inline" >
      <select name="name" id="name" lay-verify="required">
        <option value="0">请选择</option>
      </select>
    </div>
    <div class="layui-input-inline" >
      <i>必选</i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品类型名称</label>
    <div class="layui-input-inline" >
      <input name="type" type="text" id="type" value="" class="layui-input" lay-verify="required"/>
    </div>
    <div class="layui-input-inline" >
      <i>必填，不能超过50个字符</i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-inline" >
      <select name="status" lay-verify="required" lay-verify="required">
        <option value="0">请选择</option>
        <option value="1">可用</option>
        <option value="2">不可用</option>
      </select>
    </div>
    <div class="layui-input-inline" >
      <i>必选</i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">创建人</label>
    <div class="layui-input-inline" >
      <input name="createPerson" id="createPerson" type="text" value="${sessionScope.user}"  readonly="readonly" class="layui-input" />
    </div>
    <div class="layui-input-inline" >
      <i>不能编辑</i>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">创建时间</label>
    <div class="layui-input-inline" >
      <input name="createTime" id="createTime" type="text" value="" readonly="readonly" class="layui-input" />
    </div>
    <div class="layui-input-inline" >
      <i>不能编辑</i>
    </div>
  </div>
  <div class="layui-form-item">
    <button lay-submit lay-filter="formDemo" class="layui-btn btn-add">添加</button>
  </div>
</div>
</form>
<script type="text/javascript">
  layui.use(['table', 'form'], function () {
    var table = layui.table,
            form = layui.form,
            $ = layui.jquery;
    form.render();
    //品牌名称下拉列表
    $.ajax({
      url: "/PurchaseOrder/getList",
      type: "post",
      dataType: "json",
      success: function(data) {
        //var json = eval("("+data+")");
        var brand = eval("("+data.brand+")");

        //使用循环遍历，给下拉列表赋值
        $("#name").empty();
        $("#name").append(new Option("请选择",""))
        for(var i=0;i<brand.length;i++){
          $("#name").append('<option value="'+brand[i].name+'">'+brand[i].name+'</option>');
        }
        form.render("select")//重新渲染 固定写法
      }
    });
    $(function () {
      var date = new Date();
      $("#createTime").val(date.toLocaleString().replaceAll("/", "-"));
    })
    //监听提交
    form.on('submit(formDemo)', function (data) {
      $.ajax({
        url: "/GoodType/addGoodType",
        data: JSON.stringify(data.field),
        type: 'post',
        dataType: 'json',
        contentType: "application/json",
        success: function (resp) {
          layer.closeAll();
          layer.msg(resp.message, {icon: 6});
        },
        error: function () {
          layer.closeAll();
          layer.msg('系统错误，请联系管理员', {icon: 5});
        }
      });
      return false;
    });
  });
</script>
</body>
</html>
